package com.example.spzx.controller;

import com.example.spzx.Service.CategoryService;
import com.example.spzx.model.entity.product.Category;
import com.example.spzx.model.vo.common.Result;
import com.example.spzx.model.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("/admin/system/category")
@RestController
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @RequestMapping("/list")
    public Result<Category> list(){
        List<Category> categoryList=categoryService.getlist();
        return Result.build(categoryList, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse httpServletResponse){
        categoryService.exportData(httpServletResponse);

    }
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
